/************************* 版权声明 *********************************
 * 
 * 版权所有：Apache License 2.0
 * 
 ************************* 版本声明 *********************************
 *@since jdk1.5
 *@version 0.1
 ************************* 变更记录 *********************************
 *
 * 创建者：bijiqiang Email:bijiqiang@gmail.com   创建日期： 2009-12-17
 * 创建记录：创建类结构。
 * 
 * 修改者：       修改日期：
 * 修改记录：
 *
 * 修改者：       修改日期：
 * 修改记录：
 * ……
 ************************* To  Do *********************************
 *
 * 1、实现所有未实现的方法（抛出UnsupportedOperationException的方法）。
 * 
 ************************* 随   笔 *********************************
 *  转贴控制action
 * 
 * 
 ******************************************************************
 */

package com.realgodo.site.web.user.topic;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springside.modules.orm.Page;

import com.realgodo.site.entity.application.topic.Topic;
import com.realgodo.site.service.application.TopicManager;
import com.realgodo.site.web.user.UserDefaultController;

@Scope("prototype")
@Results( { @Result(name = "tomy", type = "redirect", location = "${base}/user/topic/index!my") })
public class IndexController extends UserDefaultController {

	private static final long serialVersionUID = 5074508544106758600L;

	@Autowired
	private TopicManager topicManager;

	private Page<Topic> topics = new Page<Topic>(PAGE_SIZE);
	private Topic topic;

	/**
	 * 热门转贴
	 */
	public String execute() throws Exception {
		topics= this.topicManager.getHotTopic(topics);
		return SUCCESS;
	}

	/**
	 * 初始化 发布转贴
	 * 
	 * @return
	 * @throws Exception
	 */
	public String add() throws Exception {
		return "add";
	}

	/**
	 * 获取我的转贴
	 * 
	 * @return
	 * @throws Exception
	 */
	public String my() throws Exception {
		topics = this.topicManager.getMyTopic(topics, super.getSpace());
		return "my";
	}

	/**
	 * 获取我的好友的转贴
	 * 
	 * @return
	 * @throws Exception
	 */
	public String friends() throws Exception {

		return "friends";
	}

	/**
	 * 保存我的转贴
	 * 
	 * @return
	 * @throws Exception
	 */
	public String save() throws Exception {
		if (null != super.getSpace()) {
			this.topicManager.saveTopic(topic, super.getSpace());
		}
		return "tomy";
	}

	/**
	 * 预览转贴
	 * 
	 * @return
	 * @throws Exception
	 */
	public String show() throws Exception {

		if (null != getId()) {
			topic = this.topicManager.get(getId());
		}
		return "show";
	}

	public Page<Topic> getTopics() {
		return topics;
	}

	public void setTopics(Page<Topic> topics) {
		this.topics = topics;
	}

	public Topic getTopic() {
		return topic;
	}

	public void setTopic(Topic topic) {
		this.topic = topic;
	}

}
